<template>
  <div class="alterable-label-box">
    <div v-show="!show" class="alterable-label" @dblclick="show=true">
      {{ value }}
    </div>
    <div v-show="show" class="flex-row-start alterable-label-input ">
      <input v-model="value" v-text="value"></input>
      <el-button size="mini" type="danger" @click="handleSure">✓</el-button>
      <el-button size="mini" @click="show=false">x</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: "AlterableLabel",
  props: {
    label: ""
  },
  data() {
    return {
      show: false,
      value: this.label
    }
  },
  methods: {
    handleSure() {
      this.$emit("sure", this.value)
      this.show = false
    }
  },
  watch: {
    label(newV) {
      this.value = newV
    }
  }
}
</script>

<style lang="less" scoped>
.alterable-label-box {

  width: 100%;
  height: 100%;

  .alterable-label {

  }

  .alterable-label-input {
    width: 100%;
    height: 100%;

    input {
      height: 100%;
      width: fit-content;
      border: none;
      border-bottom: 1px solid grey;
      outline: none;
      margin-right: 5px;
      color: #8c939d;
    }

  }
}
</style>